<?php

class InicioController extends AppController {

    public function inicio() {
        //Load::lib('General')
        $ip = ip2long(General::getIp());
        $url = "http://api.ipinfodb.com/v2/ip_query.php?key=17c077a658774e3b40a4bdf121994c5d3e91a3a7d27782ac80d6417f2f62ed64&ip=" . General::getIP() . "&timezone=false";
        //$url = "http://api.ipinfodb.com/v2/ip_query.php?key=17c077a658774e3b40a4bdf121994c5d3e91a3a7d27782ac80d6417f2f62ed64&ip=208.113.135.6&timezone=false";
        $xml = file_get_contents($url);
        $obj = simplexml_load_string($xml);
        $sigla_pais = Load::model('direcciones_ip')->find_first("protocolo_inicial<=" . $ip . " and protocolo_final>=" . $ip);
        //$pais = strtolower($obj->CountryCode);
        $pais = strtolower($sigla_pais->sigla);
        //Session::set('pais', $pais);
        if (is_object(Load::model('pais')->getPais($pais))) {
            Router::route_to("controller: country", "id: " . $pais . "");
        }
        else
            Router::route_to("controller: country", "id: us");
    }

    public function login() {
        View::response('view');
        if ($acceso == "privado")
            Flash::error("Zona Restringida.");
        if ($acceso == "logout")
            Flash::notice("La sesión se cerro");
        if (Input::hasPost("login")) {
            //Load::lib('auth');
            $datos = $this->post("login");
            $usuario = $datos["log"];
            $pwd = md5($datos["pwd"]);
            $auth = new Auth("model", "class: login", "usuario: $usuario", "clave: $pwd");
            if ($auth->authenticate()) {
                Router::route_to('controller: panel');
            } else {
                Flash::error("Usuario o contraseña incorrecta");
            }
        }
    }

}

?>
